﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data;
using Antu.WorkFlowFactory;

namespace WebSys.UI.Control.ZhengShou
{
    public class showfileControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            string strid = base.Page.Request["ID"];
            if (strid != null)
            {
                EluZSProvider.File file = _EluZSDataProvider.GetFileOne(strid);
                if (file != null && file.FILECONTENT != null)
                {
                    string fileext = file.SUFFIX;
					if ((fileext.ToLower() == ".xls") || (fileext.ToLower() == ".xlsx"))
                    {
                        base.Page.Response.ContentType = "application/vnd.ms-excel";//打开文件类型
                    }
                    else if ((fileext.ToLower() == ".doc") || (fileext.ToLower() == ".docx"))
                    {
                        base.Page.Response.ContentType = "application/msword";//打开文件类型
                    }
                    base.Page.Response.BufferOutput = true;
                    base.Page.Response.Clear();
                    base.Page.Response.BinaryWrite((byte[])_EluZSDataProvider.GetOneFile(strid).Rows[0]["FILECONTENT"]); //输出到网页         
                    base.Page.Response.Flush();
                }
                else {
                    DataTable dt = _FlowFactoryProvider.GetSignDT(strid);
                    if (file != null && dt.Rows[0]["SIGNPIC"] != null)
                    {
                        base.Page.Response.BufferOutput = true;
                        base.Page.Response.Clear();
                        base.Page.Response.BinaryWrite((byte[])dt.Rows[0]["SIGNPIC"]); //输出到网页         
                        base.Page.Response.Flush();
                    }
                }
            }
        }
    }
}


